﻿/**
 * 根据元数据自动生成的表格。
 */
Ext.define('Happy.tree.metadata.Panel', {
    extend: 'Happy.tree.Panel',
    alias: 'widget.happy-metadata-tree',
    mixins: {
        'custom-configable': 'Happy.mixin.CustomConfigable'
    },

    /**
     * 重写 ExtJs。
     * 
     * @protected
     */
    initComponent: function () {
        var me = this;

        Ext.applyIf(me, {
            title: me.metadata.getGridTitle(),
            storeConfig: { type: me.metadata.getTreeStoreClassName() }
        });

        me.callParent(arguments);
    },

    /**
     * 根据元数据配置 Tbar。
     * 
     * @protected
     */
    configTbar: function () {
        var me = this;

        var actions = [
            {
                type: 'new',
                showStrategy: {
                    title: me.metadata.getNewFromTitle(),
                    formType: me.metadata.getFormClassAlias(),
                    formConfig: {
                        scene: me.metadata.getNewFormSceneClassName()
                    }
                }
            },
            {
                type: 'edit',
                remoteLoad: me.metadata.isLifeCycleIndependent(),
                showStrategy: {
                    title: me.metadata.getEditFromTitle(),
                    formType: me.metadata.getFormClassAlias(),
                    formConfig: {
                        scene: me.metadata.getEditFormSceneClassName()
                    }
                }
            },
            {
                type: 'tree-delete',
                remoteDelete: me.metadata.isLifeCycleIndependent()
            }
        ];
        if (me.metadata.isLifeCycleIndependent()) {
            actions.unshift(Happy.createAction('refresh'));
        }

        me.customConfigArray(actions, 'type', 'config-tbar-');

        me.tbar = Happy.createActions(actions);

        me.callScene('configTbar', arguments);
    },

    /**
     * 根据元数据配置 Columns。
     * 
     * @protected
     */
    configColumns: function () {
        var me = this;

        me.columns = Ext.clone(me.metadata.getDefaultTreeGridColumns());

        me.customConfigArray(me.columns, 'dataIndex', 'config-column-');

        me.callScene('configColumns', arguments);
    }
});